{$CLEO}
jump @start
0662: NOP "CPad::DoCheats - now it sets value of offset _cheatString-1 into TRUE (1) if proper cheat key has been pressed"
0662: NOP "Used by TestCheat functions"
0662: NOP "Version: 1.0"
0662: NOP "Compatible with:"
0662: NOP "GTA San Andreas v1.0 [US] HOODLUM No-CD  Fixed EXE"
0662: NOP "GTA: San Andreas v1.01 [EURO] No-CD/Fixed EXE" 
0000: NOP
0662: NOP "Author: fastman92"
0662: NOP "Visit my site: fastman92.tk"

:start
{$INCLUDE functions/Detect_EXE_version.txt}

// ---------------------- redirect CPad::DoCheats ----------------------
0AB1: call_scm_func @getScriptContentPointer 0 store_script_content 0@   

0AB1: call_scm_func @GetAddress_CPad__DoCheats 0 store_offset 1@
0AB1: call_scm_func @asm_PutOnAddressJmpFarToLabel 4 script_content 0@ source_address 1@ source_virtual_protect true destination @CPad__DoCheats


// ---------------------- CPad::DoCheats layout ------------------------
0AB1: call_scm_func @GetAddress_cheatString 0 store_offset 1@
1@ -= 1
0AB1: call_scm_func @asm_PutOnLabelAbsoluteAddressToAddress 4 script_content 0@ source_label @CPad__DoCheats_mov_HasKeyBeenPressed_bl_address source_size 4 destination 1@


0AB1: call_scm_func @GetAddress_currKeyState 0 store_offset 1@  
1@ += 0x18      // CKeyState.standardKeys
0AB1: call_scm_func @asm_PutOnLabelAbsoluteAddressToAddress 4 script_content 0@ source_label @CPad__DoCheats_cmp_currKeyState_standardKeys_address source_size 4 destination 1@
0AB1: call_scm_func @asm_PutOnLabelRelativeAddressToLabel 4 script_content 0@ source_label @CPad__DoCheats_jz_incrementAndContinueLoop source_size 1 destination @CPad__DoCheats_incrementAndContinueLoop

0AB1: call_scm_func @GetAddress_prevKeyState 0 store_offset 1@
1@ += 0x18      // CKeyState.standardKeys
0AB1: call_scm_func @asm_PutOnLabelAbsoluteAddressToAddress 4 script_content 0@ source_label @CPad__DoCheats_cmp_prevKeyState_standardKeys_address source_size 4 destination 1@
0AB1: call_scm_func @asm_PutOnLabelRelativeAddressToLabel 4 script_content 0@ source_label @CPad__DoCheats_jnz_incrementAndContinueLoop_address source_size 1 destination @CPad__DoCheats_incrementAndContinueLoop

0AB1: call_scm_func @GetAddress_CPad__AddToCheatString 0 store_offset 1@
0AB1: call_scm_func @asm_PutOnLabelRelativeAddressToAddress 4 script_content 0@ source_label @CPad__DoCheats_call_CPad__AddToCheatString_address source_size 4 destination 1@

0AB1: call_scm_func @asm_PutOnLabelRelativeAddressToLabel 4 script_content 0@ source_label @CPad__DoCheats_jnge_compareKeyStates_address source_size 1 destination @CPad__DoCheats_compareKeyStates           

0A93: end_custom_thread

:CPad__DoCheats
hex
53              // push     ebx
56              // push     esi
31 DB           // xor      ebx, ebx        ; register HasKeyBeenPressed = 0
33 F6           // xor      esi, esi        ; counter = 0
31 C0           // xor      eax, eax
end

:CPad__DoCheats_compareKeyStates
hex
66 83 3C 75     // cmp      _currKeyState.standardKeys[esi*2], 0 ; supposed to be TRUE
end
      

:CPad__DoCheats_cmp_currKeyState_standardKeys_address
hex
00 00 00 00     
00

74              // jz       short incrementAndContinueLoop
end

:CPad__DoCheats_jz_incrementAndContinueLoop
hex
00

66 83 3C 75     // cmp      _prevKeyState.standardKeys[esi*2], 0 ; supposed to FALSE
end 

:CPad__DoCheats_cmp_prevKeyState_standardKeys_address
hex 
00 00 00 00
00

75              // jne     short incrementAndContinueLoop
end

:CPad__DoCheats_jnz_incrementAndContinueLoop_address
hex
00

B3 01           // mov bl,01

56              // push     esi     ; pressed character
E8              // call     CPad__AddToCheatString
end

:CPad__DoCheats_call_CPad__AddToCheatString_address
hex
00 00 00 00

83 C4 04        // add      esp, 4
end

:CPad__DoCheats_incrementAndContinueLoop

hex
46              // inc esi  ; counter
81 FE 00 01 00 00       // cmp      esi, 256
end

hex
7C              // jnge     short compareKeyStates
end

:CPad__DoCheats_jnge_compareKeyStates_address
hex
00

88 1D           // mov      [HasKeyBeenPressed], bl
end

:CPad__DoCheats_mov_HasKeyBeenPressed_bl_address
hex
00 00 00 00
 
5E              // pop      esi
5B              // pop      ebx
C3              // retn
end 

:TestCheat_initialize_end
{$INCLUDE general/Addresses.txt}
{$INCLUDE functions/ArrayGetValueByIndex.txt}
{$INCLUDE functions/asm_handling.txt}
{$INCLUDE functions/getScriptContentPointer.txt}